import {
	showSuccess,
	showFail
} from "@/js/toast.js"
export const dataBaseMixin = {
	data() {
		return {

		}
	},
	methods: {
		// 数据库操作
		getAllData() {
			uniCloud.callFunction({
				name: 'getDouyinData',
				success: (data) => {
					// showSuccess()
					const res = data.result.data
					if (!res) return
					for (let i = 0; i < res.length; i++) {
						const item = res[i]
						this[item.key] = item.data
						console.log(this[item.key]);
					}
				},
				fail: () => {
					showFail()
				}
			});
		},
		getData(key) {
			uniCloud.callFunction({
				name: 'getDouyinData',
				success: (data) => {
					// showSuccess()
					const res = data.result.data.find(o => o.key == key)
					if (!res) return
					this.data = res.data
					// console.log(this.data);
				},
				fail: () => {
					showFail()
				}
			});
		},
		updateData(key) {
			const data = this.data
			const id = data._id
			uniCloud.callFunction({
				name: 'updateDouyinData',
				data: {
					id,
					key,
					data,
				},
				success: (data) => {
					showSuccess()
					// console.log(data);
				},
				fail: () => {
					showFail()
				}
			});
		},
	}
}
